import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import Home from '../views/Home.vue'
import { BizConfigUtils } from '@/common/biz-config-utils'
import { message, Modal } from 'ant-design-vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/home',
    name: 'Home1',
    component: Home
  },
  {
    path: '/a',
    name: 'About',
    component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  },
  {
    path: '/work-ticket/work-ticket',
    name: 'WorkTicket',
    component: () => import(/* webpackChunkName: "work-ticket" */ '../views/work-ticket/work-ticket.vue')
  },
  {
    path: '/work-ticket/work-ticket/form',
    name: 'WorkTicketForm',
    component: () => import(/* webpackChunkName: "work-ticket" */ '../views/work-ticket/work-ticket-form.vue')
  },
  {
    path: '/work-ticket/work-ticket/form/:id',
    name: 'WorkTicketFormId',
    component: () => import(/* webpackChunkName: "work-ticket" */ '../views/work-ticket/work-ticket-form.vue')
  },
  {
    path: '/work-ticket/work-ticket/template-form/:teamId',
    name: 'WorkTicketFormTeamId',
    component: () => import(/* webpackChunkName: "work-ticket" */ '../views/work-ticket/work-ticket-template-form.vue')
  },
  {
    path: '/person/person',
    name: 'Person',
    component: () => import(/* webpackChunkName: "person" */ '../views/person/person.vue')
  },
  {
    path: '/person/person/form',
    name: 'PersonForm',
    component: () => import(/* webpackChunkName: "person" */ '../views/person/person-form.vue')
  },
  {
    path: '/person/person/form/success',
    name: 'PersonFormSuccess',
    component: () => import(/* webpackChunkName: "person" */ '../views/person/person-form-success.vue')
  },
  {
    path: '/person/person/form/:id',
    name: 'PersonFormId',
    component: () => import(/* webpackChunkName: "person" */ '../views/person/person-form.vue')
  },
  {
    path: '/device/device',
    name: 'Device',
    component: () => import(/* webpackChunkName: "device" */ '../views/device/device.vue')
  },
  {
    path: '/device/device/form',
    name: 'DeviceForm',
    component: () => import(/* webpackChunkName: "device" */ '../views/device/device-form.vue')
  },
  {
    path: '/device/device/form/success',
    name: 'DeviceFormSuccess',
    component: () => import(/* webpackChunkName: "device" */ '../views/device/device-form-success.vue')
  },
  {
    path: '/device/device/form/:id',
    name: 'DeviceFormId',
    component: () => import(/* webpackChunkName: "device" */ '../views/device/device-form.vue')
  },
  {
    path: '/team/team',
    name: 'Team',
    component: () => import(/* webpackChunkName: "team" */ '../views/team/team.vue')
  },
  {
    path: '/team/team/form',
    name: 'TeamForm',
    component: () => import(/* webpackChunkName: "team" */ '../views/team/team-form.vue')
  },
  {
    path: '/team/team/form/success',
    name: 'TeamFormSuccess',
    component: () => import(/* webpackChunkName: "team" */ '../views/team/team-form-success.vue')
  },
  {
    path: '/team/team/form/:id',
    name: 'TeamFormId',
    component: () => import(/* webpackChunkName: "team" */ '../views/team/team-form.vue')
  },
  {
    path: '/login/login',
    name: 'login',
    component: () => import(/* webpackChunkName: "login" */ '../views/login/login.vue')
  },
  {
    path: '/word-template/word-template',
    name: 'wordtemplate',
    component: () => import(/* webpackChunkName: "wordtemplate" */ '../views/word-template/word-template.vue')
  },
  {
    path: '/duty/duty',
    name: 'duty',
    component: () => import(/* webpackChunkName: "duty" */ '../views/duty/duty.vue')
  },
  {
    path: '/duty-plan/duty-plan',
    name: 'duty-plan',
    component: () => import(/* webpackChunkName: "duty-plan" */ '../views/duty-plan/duty-plan.vue')
  },
  {
    path: '/work-ticket-handle/work-ticket-handle',
    name: 'work-ticket-handle',
    component: () => import(/* webpackChunkName: "work-ticket-handle" */ '../views/work-ticket-handle/work-ticket-handle.vue')
  },
  {
    path: '/test/test01',
    name: 'test',
    component: () => import(/* webpackChunkName: "test" */ '../views/test/test01.vue')
  }
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})
router.beforeEach((to, from) => {
  console.log('to', to)
  const loginUser = BizConfigUtils.getLoginUser()
  if (loginUser === null && (to.fullPath.startsWith('/work-ticket/work-ticket') || to.fullPath.startsWith('/device/device'))) {
    const modal = Modal.warning({
      content: '请选择一条数据作为登录身份',
      okText: '确定'
    })
    router.push('/home')
    return false
    // return true
  } else {
    return true
  }
})
export default router
